namespace Pic.Web.Controllers
{
    using Castle.MonoRail.Framework;
    using Castle.MonoRail.Framework.Helpers;
    using Pic.Model;
    using System.Collections;
    using System.Collections.Generic;
    using NHibernate.Expression;
    using System;

    public class PartController : SmartDispatcherController
    {
        public void GetCommend(string albumID)
        {
            Pic_Album album = Pic_Album.Find(int.Parse(albumID));
            IList dataSource = Pic_Comment.FindAll(Order.Desc("Pic_CommentID"), Expression.Eq("Pic_Album", album));
            PropertyBag["Comments"] = PaginationHelper.CreatePagination(this, dataSource, 4);
        }

        public void vote(string m) {
            Pic_Album album = Pic_Album.Find(int.Parse(m));
            album.Vote++;
            album.Update();
            PropertyBag["VoteNum"] = album.Vote;
        }

        public void fav(string m) {
            Pic_Member member = (Pic_Member)Session["Member"];
            if (member != null) {
                try
                {
                    Pic_Album album = Pic_Album.Find(int.Parse(m));
                    Pic_Favorite fav = new Pic_Favorite();
                    fav.Pic_Album = album;
                    fav.Pic_Member = member;
                    fav.Save();
                    album.FavNum++;
                    album.Update();
                }
                catch (Exception e) { }
            }
        }
    }
}
